<?php
declare(strict_types=1);

namespace app\adminapi\controller\v1;


use app\common\model\addon\Addons as AddonsModel;
use hiduoke\services\cloud\DiyCloud;
use think\App;
use app\common\controller\AdminController;

class Index extends AdminController
{
    /**
     * @var string[] 无需登录的action
     */
//    protected $notLogin = ['*'];
//    protected $notCheck = ['api'];
    /**
     * @var AddonsModel
     */
    private AddonsModel $model;

    /**
     * @var DiyCloud
     */
    private DiyCloud $Diy;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new AddonsModel();
    }

    public function index()
    {
        return $this->success('ok');
    }

    public function removeAddonAuth($auth, $userAuth)
    {
        $new_auth = [];

        if (!in_array("all", $userAuth)) {

            foreach ($auth as $k => $v) {
                if (isset($v['children'])) {
                    $new_auth[] = [
                        'key'      => $v['key'],
                        'label'    => $v['label'],
                        'children' => $this->removeAddonAuth($v['children'], $userAuth)
                    ];
                } else {
                    if (in_array($v['key'], $userAuth)) {
                        $new_auth[] = $v;
                    }
                }
            }
        } else {
            $new_auth = $auth;
        }
        return $new_auth;
    }
}
